package com.qd.panda.etc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.sys.annotation.OperatorInfo;
import com.qd.common.sys.enums.OperatorType;
import com.qd.common.panda.domain.entity.etc.EtcJumpDTO;
import com.qd.panda.service.etc.EtcJumpService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * ETC/WEB_跳转记录
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/etcJump/")
@Slf4j
public class EtcJumpController {
    private final EtcJumpService etcJumpService;


    /**
     * 获取跳转记录
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/getById")
    public EtcJumpDTO getById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return etcJumpService.getByIdDto(id);
    }

    /**
     * 跳转记录列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/page")
    public IPage<EtcJumpDTO> page(EtcJumpDTO dto) {
        return etcJumpService.page(PageUtil.buildPage(dto), dto);
    }

    /**
     * 跳转记录导出
     *
     * @param query 查询参数
     */
    @PreAuthorize("@ps.hasPermission('system:etcJump:export')")
    @OperatorInfo(title = "导出", operator = OperatorType.EXPORT)
    @GetMapping(value = "/export")
    public void export(EtcJumpDTO query) {
        etcJumpService.export(query);
    }
}